$('#slider1').slider();
var vm = new Vue({
	el: '#app',
	data: {
		items: [],
		loaded: false
	},
	mounted: function() {
		getTransferAccounts();
		index();
	}
});

function index() {
	$.ajax({
		type: "GET",
		url: ip + "trade/finance/serverGetUserAccountList.o",
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		success: function(data) {
			if(data.statusCode == 0) {
				vm.loaded = true;
				$("#img").attr("src",data.result[0].tradeCoin.img);
				$("#title").text(data.result[0].tradeCoin.title);
				$("#balanceAmount").text(data.result[0].unFreezeAmount);
			} else if(data.statusCode == 1000) {
				loginError();
			} else {
				$.toptip(data.resultDesc, 'error');
			}
		}
	});
}
window.onbeforeunload = function(e) {
	localStorage.removeItem('txl2');
}

function getTransferAccounts() {
	var txl2 = localStorage.getItem("txl2");
	$("#money").val(txl2);
}
/**
 * 扫描二维码并且解析
 */
function startCan() {
	mui.openWindow({
		createNew:false,// 打开并且刷新：true刷新，false不刷新
		show:{
			autoShow:true,
			aniShow:'fade-in',
		},
		url: 'qr.html',
		id: 'qr'
	});
}

var first = true;

function serverTransOut() {
	//$(".weui-btn").attr("disabled", false);
	var serverTransOutReqbody = {
		"addr": $("#money").val().trim(),
		"password": $("#payPwd").val().trim(),
		"num": $("#num").val().trim()
	};
	if(first) {
		first = false;
		$.ajax({
			type: "POST",
			url: ip + "platform/transfer/userTransfer.m",
			xhrFields: {
				withCredentials: true
			},
			crossDomain: true,
			data: serverTransOutReqbody,
			success: function(data) {
				if(data.statusCode == 0) {
					//$(".weui-btn").attr("disabled", true);
					$.toptip("转赠成功！", 'success');
					setTimeout(function(){
				        mui.openWindow({
							createNew: true, // 打开并且刷新：true刷新，false不刷新
							show: {
								autoShow: true,
								aniShow: 'fade-in'
							},
							url: 'homePage.html',
							id: 'homePage'
						});
				    },1000);
				} else if(data.statusCode == 1000) {
					loginError();
				} else {
					$.toptip(data.resultDesc, 'error');
					first = true;
				}
			}
		});
	}
}! function($, ydui) {
	var dialog = ydui.dialog;
	var $keyboard = $('#J_KeyBoard');
	// 初始化参数
	$keyboard.keyBoard({
		disorder: true, // 是否打乱数字顺序
		title: 'HMS安全键盘' // 显示标题
	});
	// 打开键盘
	$('.J_OpenKeyBoard').on('click', function() {
		$keyboard.keyBoard('open');
	});
	// 六位密码输入完毕后执行
	$keyboard.on('done.ydui.keyboard', function(ret) {
		$(".J_OpenKeyBoard").val(ret.password);
		// 关闭键盘
		$keyboard.keyBoard('close');
	});
}(jQuery, YDUI);